/**
 * 
 */
package guice.trails.cardeal;

import java.util.List;

import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;

/**
 * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
 * @version $Id$
 */
public class CarDeal {

	private Customer customer;

	private CarDealer dealer;

	@Inject
	public CarDeal(Customer customer, CarDealer dealer) {
		super();
		this.customer = customer;
		this.dealer = dealer;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Injector injector = Guice.createInjector(new MainModule());

		// set up a car deal between a customer and dealer
		CarDeal deal = injector.getInstance(CarDeal.class);

		try {
			Ford car = deal.dealer.request(Ford.class);
			System.out.println(String.format("%s car %s is available.", car.getClass().getSimpleName(), car.hashCode()));
		} catch (OutOfStockException e) {
			e.printStackTrace();
		}

		try {
			Toyota car = deal.dealer.request(Toyota.class);
			System.out.println(String.format("%s car %s is available.", car.getClass().getSimpleName(), car.hashCode()));
		} catch (OutOfStockException e) {
			e.printStackTrace();
		}

		// Bulk order
		try {
			int qty = 50;
			List<Toyota> car = deal.dealer.request(Toyota.class, qty);
			System.out.println(String.format("%s of %s car are available.", qty, car.getClass().getSimpleName()));
		} catch (OutOfStockException e) {
			e.printStackTrace();
		}

	}

}
